package from;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.Radio;
import org.apache.wicket.markup.html.form.RadioGroup;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.Model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RadioGroupPage extends WebPage {

    private static List SITES = new ArrayList();
    private static Map NAMES = new HashMap();

    static {
        SITES.add("http://aa.com");
        SITES.add("http://bb.com");
        SITES.add("http://cc.com");

        NAMES.put("http://aa.com", "aa");
        NAMES.put("http://bb.com", "bb");
        NAMES.put("http://cc.com", "cc");
    }

    public RadioGroupPage(){
        super();

        Form<Object> form = new Form<>("formRG");
        add(form);

        RadioGroup radioGroup = new RadioGroup("radioGroup");

        form.add(radioGroup);

        ListView sites = new ListView("sites",SITES) {
            @Override
            protected void populateItem(ListItem item) {
                Object object = item.getModelObject();
                item.add(new Radio<>("radio",new Model<>(Integer.toString(item.getIndex()))));
                item.add(new Label("name",new Model<>((Serializable)NAMES.get(object))));
            };
        };
        radioGroup.add(sites);
    }
}
